package com.csd.action.security;

import sun.management.resources.agent;

import com.csd.helper.ActionResult;
import com.csd.helper.IConstant;
import com.csd.helper.SessionManager;
import com.csd.serviceImpl.ManagerService;
import com.csd.serviceImpl.TeacherService;
import com.csd.serviceImpl.TeamService;
import com.csd.vo.UserVO;
import com.sun.org.apache.bcel.internal.generic.RETURN;

/**
 * 
 * Action:修改密码
 * 
 * @author csd
 * @version 1.0
 * 
 * <br>
 *          修订时间：2009-12-17 <br>
 *          修改原因：创建文件 <br>
 *          修改人：何文深 <br>
 * 
 */
public class PasswordSaveAction {
	/** 新密码 */
	private String newPassword;
	/** 旧密码 */
	private String oldPassword;

	public String getOldPassword() {
		return oldPassword;
	}

	public void setOldPassword(String oldPassword) {
		this.oldPassword = oldPassword;
	}

	private TeamService teamService;

	private TeacherService teacherService;

	private ManagerService managerService;

	public String getNewPassword() {
		return newPassword;
	}

	public void setNewPassword(String newPassword) {
		this.newPassword = newPassword;
	}

	public TeamService getTeamService() {
		return teamService;
	}

	public void setTeamService(TeamService teamService) {
		this.teamService = teamService;
	}

	public TeacherService getTeacherService() {
		return teacherService;
	}

	public void setTeacherService(TeacherService teacherService) {
		this.teacherService = teacherService;
	}

	public ManagerService getManagerService() {
		return managerService;
	}

	public void setManagerService(ManagerService managerService) {
		this.managerService = managerService;
	}

	public String execute() {
		String result = ActionResult.fail;
		UserVO vo = SessionManager.getUserVO();
		boolean flag = false;
		//根据登陆用户的角色调用不同服务，修改密码
		if (vo != null) {
			if (vo.getType() == IConstant.teamRole) {
				flag = teamService.resetPassword(oldPassword, newPassword);
				result = "team";
			} else if (vo.getType() == IConstant.teacherRole) {
				flag = teacherService.resetPassword(oldPassword, newPassword);
				result = "teacher";
			} else if (vo.getType() == IConstant.managerRole) {
				flag = managerService.resetPassword(oldPassword, newPassword);
				result = "manager";
			}
		}
        if(flag == false ){
        	result = "fail";
        }
		return result;
	}
}
